<?php

namespace App\Observers\Admin;

use App\Models\UserHasSection;
use Illuminate\Support\Facades\Redis;

class UserHasSectionObserver
{
    /**
     * Handle the UserHasSection "created" event.
     *
     * @param UserHasSection $userHasSection
     * @return void
     */
    public function created(UserHasSection $userHasSection)
    {

    }

    /**
     * Handle the UserHasSection "updated" event.
     *
     * @param UserHasSection $userHasSection
     * @return void
     */
    public function updated(UserHasSection $userHasSection)
    {
        // 判断某个字段是否被修改
        if ($userHasSection->isDirty()){
            $redis = Redis::connection();
            $redis->del(auth()->id().':section');
        }
    }

    /**
     * Handle the UserHasSection "deleted" event.
     *
     * @param UserHasSection $userHasSection
     * @return void
     */
    public function deleted(UserHasSection $userHasSection)
    {
        //
    }

    /**
     * Handle the UserHasSection "restored" event.
     *
     * @param UserHasSection $userHasSection
     * @return void
     */
    public function restored(UserHasSection $userHasSection)
    {
        //
    }

    /**
     * Handle the UserHasSection "force deleted" event.
     *
     * @param UserHasSection $userHasSection
     * @return void
     */
    public function forceDeleted(UserHasSection $userHasSection)
    {
        //
    }
}
